package operations;

import books.Book;
import books.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    public void work(BookList bookList){
        System.out.println("添加图书");

        //先输入nextLine后输入nextInt
        //不然需要在nextInt后读取回车
        System.out.println("请输入要添加的图书名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        System.out.println("请输入要添加的图书作者");
        String author = scanner.nextLine();

//        System.out.println("请输入要添加的图书价格");
//        int price = scanner.nextInt();
//        scanner.nextLine();

        System.out.println("请输入要添加的图书类型");
        String type = scanner.nextLine();

        System.out.println("请输入要添加的图书价格");
        int price = scanner.nextInt();


        Book book = new Book(name,author,price,type);
        //获取当前存放书的位置
        int currentSize= bookList.usedSize;
        //把书存放在指定位置(下标即对应位置)
        bookList.setBooks(book,currentSize);
        //将书的有效个数+1
        bookList.setUsedSize(currentSize+1);
    }
}
